package com.yangjun.service.report;

import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.yangjun.common.ServerResponse;
import com.yangjun.common.enums.report.ReportTemplateTypeEnum;
import com.yangjun.dao.mybatis.mapper.report.DataBaseExcelDefinitionMapper;
import com.yangjun.dao.mybatis.mapper.report.ReportExportStatusMapper;
import com.yangjun.dao.mybatis.mapper.report.ReportImportStatusMapper;
import com.yangjun.dao.mybatis.mapper.usermanage.ExcelRoleManagerMapper;
import com.yangjun.entity.report.DvExcelFieldDefinitionEntity;
import com.yangjun.entity.report.DvReportExportStatus;
import com.yangjun.entity.report.DvReportImportStatus;
import com.yangjun.service.common.CommonService;
import com.yangjun.service.permission.ReportExportPermissionService;
import com.yangjun.utils.DvDateUtils;
import com.yangjun.utils.POIExcelUtils;
import com.yangjun.vo.report.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;
@Service
public class ReportCommonService {
	@Autowired
	private ReportImportStatusMapper reportImportStatusMapper;
	@Autowired
	private ReportExportStatusMapper reportExportStatusMapper;
	@Value("${excel.uploadPath}")
    private String uploadPath;
	@Autowired
	private DataBaseExcelDefinitionMapper dataBaseExcelDefinitionMapper;
	@Autowired
	private ReportExportPermissionService reportExportPermissionService;
	@Autowired
	private ExcelRoleManagerMapper excelRoleManagerMapper;
	@Autowired
	private TargetMemberReprotExportService targetMemberReprotExportService;
	@Autowired
	private TMallRxReprotExportService tMallRxReprotExportService;
	@Autowired
	private SingleProductReprotExportService singleProductReprotExportService;
	@Autowired
	private CommodityFlowReprotExportService commodityFlowReprotExportService;
	@Autowired
	private ProductInfoReprotExportService productInfoReprotExportService;
	@Autowired
	private ActivePackageReprotExportService activePackageReprotExportService;
	@Autowired
	private OrderTransactionReprotExportService orderTransactionReprotExportService;
	@Autowired
	private InventoryReprotExportService inventoryReprotExportService;	
	@Autowired
	private CommonService commonService;
	@Autowired
	private StoragePeriodReprotExportService storagePeriodReprotExportService;
	
	
	private String[] quertReporttype(){
		return dataBaseExcelDefinitionMapper.queryExcelId();
	}
	
	public List<Map<String,Object>> getSearchTemplate(String[] templateCodeArr,String searchName){
		List<Map<String,Object>> searchWayList = Lists.newArrayList();
		for(String templateCode : templateCodeArr){
			Map<String,Object> searchMap = Maps.newHashMap();
			Boolean selected = false;
			searchMap.put("searchWayName", ReportTemplateTypeEnum.getTemplateName(templateCode));
			searchMap.put("searchWayValue", templateCode);
			if(searchName.equals(templateCode)){
				selected = true;
			}
			searchMap.put("selected", selected);
			searchWayList.add(searchMap);
		}
		return searchWayList;
	}
	
	public int saveReportStatus(String username,String reportid,String userid,String reportUUID,String reportName,String fileName){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		DvReportImportStatus dvReportImportStatus = new DvReportImportStatus();
		try {
			dvReportImportStatus.setId(reportUUID);
			dvReportImportStatus.setDateDay(sdf.parse(sdf.format(new Date())));
			dvReportImportStatus.setReportId(reportid);
			dvReportImportStatus.setReportName(reportName);
			dvReportImportStatus.setHandler(username);
			dvReportImportStatus.setStatus(0);
			dvReportImportStatus.setImportTime(null);
			dvReportImportStatus.setUploadTime(new Date());
			dvReportImportStatus.setUserid(userid);
			dvReportImportStatus.setFileName(fileName);
		} catch (Exception e) {
			e.printStackTrace();
		}
		int result = reportImportStatusMapper.insertReportStatus(dvReportImportStatus);
		return result;
	}
	
	public void downloadTemplet(HttpServletResponse response,String reportName){
		if(StringUtils.isNotBlank(reportName)){
			byte[] buff = new byte[1024];
			BufferedInputStream bis = null;
			OutputStream os = null;
			BufferedOutputStream bos = null;
			try {
				reportName = reportName+".xlsx";
				ClassPathResource resource = new ClassPathResource("excelTemplet/"+reportName);
				
				response.setHeader("conent-type", "application/octet-stream");  
	            response.setContentType("application/octet-stream"); 
				response.setHeader("Content-Disposition", "attachment;filename=" + new String( reportName.getBytes("UTF-8"), "ISO8859-1" ));
				os = response.getOutputStream();
				bos = new BufferedOutputStream(os);  
				bis = new BufferedInputStream(resource.getInputStream());
				int length = 0;
				while((length = bis.read(buff))!=-1){
					bos.write(buff, 0, length);
				}
				bos.flush();
			} catch (IOException e) {
				e.printStackTrace();
			}finally{
				if(bis!=null){
					try {
						bis.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
				if(bos!=null){
					try {
						bos.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
		}
	}
	
	
	private void updateMyReport(String userid){
//		if("18".equals(userid)||"507".equals(userid)||"715".equals(userid)||"6".equals(userid)||"518".equals(userid)||"141".equals(userid)||"481".equals(userid)){
			List<DvReportExportStatus> reportExportStatusList = reportExportStatusMapper.queryMyReport(userid);
			if(reportExportStatusList.size()>0){
				for(DvReportExportStatus reportExportStatus : reportExportStatusList){
					String reporttype = reportExportStatus.getReporttype();
					String[] allowFieldArr = reportExportPermissionService.getReportAllowField(userid, reporttype);
					List<String> dimList = reportExportPermissionService.getUserExcelDimSet(userid, reporttype);
					String[] dimArr = dimList.toArray(new String[dimList.size()]);
					if("productInfo".equals(reporttype)){
						ProductInfoReportExportVO pireVo = JSON.parseObject(reportExportStatus.getReportparam(), ProductInfoReportExportVO.class);
						pireVo.setTarget(updateAuthorityTarget(pireVo.getTarget(),allowFieldArr));
						productInfoReprotExportService.addOrUpdateReport(pireVo);
					}else if("commodityFlow".equals(reporttype)){
						CommodityFlowReportExportVO cfreVo = JSON.parseObject(reportExportStatus.getReportparam(), CommodityFlowReportExportVO.class);
						//平台维度权限页面根据中文名字进行权限判断
						int type = reportExportPermissionService.getManagerType(userid, reporttype);
						if(type==1){
							cfreVo.setTarget(updateAuthorityTarget(cfreVo.getTarget(),allowFieldArr));
							//获取授权的平台470
							List<Map<String, Object>> ordersourceList = commonService.getOrderSource(type,cfreVo.getUserid(),reporttype);
							//之前保存的平台跟更新权限之后的平台进行匹配
							cfreVo.setOrdersource(updateAuthoritySource(cfreVo.getOrdersource(),
									Arrays.asList(getOrderSourceArr(dimArr,ordersourceList))));
							commodityFlowReprotExportService.addOrUpdateReport(cfreVo);
						}						
					}else if("singleProduct".equals(reporttype)){
						SingleProductReportExportVO spreVo = JSON.parseObject(reportExportStatus.getReportparam(), SingleProductReportExportVO.class);
						//平台维度权限页面根据中文名字进行权限判断
						int type = reportExportPermissionService.getManagerType(userid, reporttype);
						if(type==1){
							spreVo.setTarget(updateAuthorityTarget(spreVo.getTarget(),allowFieldArr));
							//获取授权的平台470
							List<Map<String, Object>> ordersourceList = commonService.getOrderSource(type,spreVo.getUserid(),reporttype);
							//之前保存的平台跟更新权限之后的平台进行匹配
							spreVo.setOrdersource(updateAuthoritySource(spreVo.getOrdersource(),
									Arrays.asList(getOrderSourceArr(dimArr,ordersourceList))));
							singleProductReprotExportService.addOrUpdateReport(spreVo);
						}
					}else if("tmallRx".equals(reporttype)){
						TMallRxReportExportVO tmrxreVo = JSON.parseObject(reportExportStatus.getReportparam(), TMallRxReportExportVO.class);
						tmrxreVo.setTarget(updateAuthorityTarget(tmrxreVo.getTarget(),allowFieldArr));
						tMallRxReprotExportService.addOrUpdateReport(tmrxreVo);
					}else if("targetMember".equals(reporttype)){
						TargetMemberReportExportVO tmreVo = JSON.parseObject(reportExportStatus.getReportparam(), TargetMemberReportExportVO.class);
						tmreVo.setTarget(updateAuthorityTarget(tmreVo.getTarget(),allowFieldArr));
						tmreVo.setCussourceNameArr(updateAuthoritySource(tmreVo.getCussourceNameArr(), dimList));
						targetMemberReprotExportService.addOrUpdateReport(tmreVo);
					}else if("activePackage".equals(reporttype)){
						ActivePackageReportExportVO apreVo = JSON.parseObject(reportExportStatus.getReportparam(), ActivePackageReportExportVO.class);
						apreVo.setTarget(updateAuthorityTarget(apreVo.getTarget(),allowFieldArr));
						List<Map<String, Object>> ordersourceList = commonService.getOrderSource(1,apreVo.getUserid(),reporttype);
						//之前保存的平台跟更新权限之后的平台进行匹配
						apreVo.setOrdersource(updateAuthoritySource(apreVo.getOrdersource(),
								Arrays.asList(getOrderSourceArr(dimArr,ordersourceList))));
						activePackageReprotExportService.addOrUpdateReport(apreVo);
					}else if("orderTransaction".equals(reporttype)){
						OrderTransactionReportExportVO otreVo = JSON.parseObject(reportExportStatus.getReportparam(), OrderTransactionReportExportVO.class);
						//获取授权的订单交易报表类型
						List<String> orderAnalysisTypeList = commonService.getOrderAnalysisType(otreVo.getUserid(),reporttype);
						otreVo.setAnalysisType(updateAuthorityOrderAnalysis(otreVo.getAnalysisType(),orderAnalysisTypeList));
						if(StringUtils.isNotBlank(otreVo.getAnalysisType())){
							//平台维度权限页面根据中文名字进行权限判断
							int type = reportExportPermissionService.getManagerType(userid, reporttype);
							if(type==1){
								otreVo.setTarget(updateAuthorityTarget(otreVo.getTarget(),allowFieldArr));
								//获取授权的平台
								List<Map<String, Object>> ordersourceList = commonService.getOrderSource(type,otreVo.getUserid(),reporttype);
								//之前保存的平台跟更新权限之后的平台进行匹配
								otreVo.setOrdersource(updateAuthoritySource(otreVo.getOrdersource(),
										Arrays.asList(getOrderSourceArr(dimArr,ordersourceList))));
								orderTransactionReprotExportService.addOrUpdateReport(otreVo);
							}
						}else{
							reportExportStatusMapper.deleteReportStatus(otreVo.getReportid());
						}
					}else if("inventory".equals(reporttype)){
						InventoryReportExportVO itreVo = JSON.parseObject(reportExportStatus.getReportparam(), InventoryReportExportVO.class);
						itreVo.setTarget(updateAuthorityTarget(itreVo.getTarget(),allowFieldArr));
						inventoryReprotExportService.addOrUpdateReport(itreVo);
					}else if("storagePeriod".equals(reporttype)){
						StoragePeriodReportExportVO spreVo = JSON.parseObject(reportExportStatus.getReportparam(), StoragePeriodReportExportVO.class);
						//平台维度权限页面根据中文名字进行权限判断
						spreVo.setTarget(updateAuthorityTarget(spreVo.getTarget(),allowFieldArr));
						spreVo.setOrgname(commonService.getDim(spreVo.getUserid(), reporttype, spreVo.getOrgname()));
						spreVo.setQueryRange(DvDateUtils.getCurrentDate(new Date()));
						storagePeriodReprotExportService.addOrUpdateReport(spreVo);
					}
					
				}
			}
//		}
	}
	/**
	 * 
	 * @Description 查询报表更新平台权限
	 * @param sourceArr
	 * @param allowSourceList
	 * @param reporttype
	 * @return
	 * @author yangjun
	 * @Date 2017年9月19日 下午2:07:45
	 */
	private String[] updateAuthoritySource(String[] sourceArr,List<String> allowSourceList){
		List<String> resultList = Lists.newArrayList();
		for(String source : sourceArr ){
			if(allowSourceList!=null&&allowSourceList.contains(source)){
				resultList.add(source);
			}
		}
		return resultList.toArray(new String[resultList.size()]);
	}
	
	private String updateAuthorityOrderAnalysis(String orderAnalysisType,List<String> analysisTypeList){
		String result = null;
		if(analysisTypeList.contains(orderAnalysisType)){
			result = orderAnalysisType;
		}
		return result;
	}
	
	/**
	 * 
	 * @Description 查询报表更新指标权限
	 * @param targetArr
	 * @param allowFieldArr
	 * @return
	 * @author yangjun
	 * @Date 2017年9月19日 下午2:37:49
	 */
	private String[] updateAuthorityTarget(String[] targetArr,String[] allowFieldArr){
		List<String> newTargetList = Lists.newArrayList(); 
		if(allowFieldArr!=null&&allowFieldArr.length>0){
			for(String target : targetArr){
				for(String allowField : allowFieldArr){
					if(target.equals(allowField)){
						newTargetList.add(target);
					}
				}
			}
		}
		return newTargetList.toArray(new String[newTargetList.size()]);
	}
	public Object queryMyReport(String userid){
//		userid="383";
		String[] reporttypeArr = quertReporttype();
		updateMyReport(userid);
		List<DvReportExportStatus> reportExportStatusList = reportExportStatusMapper.queryMyReport(userid);
		
		List<String> reportTypeList = excelRoleManagerMapper.getUserExcelReportType(userid);
		Map<String,List<Object>> map = Maps.newHashMap();
		List<Map<String,String>> reportNameList = Lists.newArrayList();
		Map<String,Object> resultMap = Maps.newHashMap();
		for(String reporttype : reporttypeArr){
			map.put(reporttype, Lists.newArrayList());
		}
		if(reportExportStatusList.size()>0){
			for(DvReportExportStatus reportExportStatus : reportExportStatusList){
				if(reportTypeList==null){
					break;
				}
				String reporttype = reportExportStatus.getReporttype();
				if(!reportTypeList.contains(reporttype)){
					continue;
				}
				String reportname = reportExportStatus.getReportName();
				String reportid = reportExportStatus.getReportid();
				String createtime = DvDateUtils.format(reportExportStatus.getCreatetime(), "yyyy-MM-dd HH:mm:ss");
				Object obj = null;
				if("productInfo".equals(reporttype)){
					ProductInfoReportManageVO pirmVO = JSON.parseObject(reportExportStatus.getReportManageParam(), ProductInfoReportManageVO.class);
					obj = pirmVO;
				}else if("commodityFlow".equals(reporttype)){
					CommodityFlowReportManageVO cfrmVO = JSON.parseObject(reportExportStatus.getReportManageParam(), CommodityFlowReportManageVO.class);
					obj = cfrmVO;
				}else if("singleProduct".equals(reporttype)){
					SingleProductReportManageVO sprmVo = JSON.parseObject(reportExportStatus.getReportManageParam(), SingleProductReportManageVO.class);
					obj = sprmVo;
				}else if("tmallRx".equals(reporttype)){
					TMallRxReportManageVO tmrxreVo = JSON.parseObject(reportExportStatus.getReportManageParam(), TMallRxReportManageVO.class);
					obj = tmrxreVo;
				}else if("targetMember".equals(reporttype)){
					TargetMemberReportManageVO tmreVo = JSON.parseObject(reportExportStatus.getReportManageParam(), TargetMemberReportManageVO.class);
					obj = tmreVo;
				}else if("activePackage".equals(reporttype)){
					AcitvePackageReportManageVO apreVo = JSON.parseObject(reportExportStatus.getReportManageParam(), AcitvePackageReportManageVO.class);
					obj = apreVo;
				}else if("orderTransaction".equals(reporttype)){
					OrderTransactionReportManageVO otreVo = JSON.parseObject(reportExportStatus.getReportManageParam(), OrderTransactionReportManageVO.class);
					obj = otreVo;
				}else if("inventory".equals(reporttype)){
					InventoryReportManageVO itreVo = JSON.parseObject(reportExportStatus.getReportManageParam(), InventoryReportManageVO.class);
					obj = itreVo;
				}else if("storagePeriod".equals(reporttype)){
					StoragePeriodReportManageVO spreVo = JSON.parseObject(reportExportStatus.getReportManageParam(), StoragePeriodReportManageVO.class);
					obj = spreVo;
				}
				
				List<Object> list = map.get(reporttype);
				list.add(obj);
				
				Map<String,String> itemReportNameMap = Maps.newHashMap();
				itemReportNameMap.put("name", reportname);
				itemReportNameMap.put("value", reportid);
				itemReportNameMap.put("reporttype", reporttype);
				itemReportNameMap.put("createtime", createtime);
				reportNameList.add(itemReportNameMap);
			}
		}
		List<Map<String,String>> reportNameResultList = Lists.newArrayList();
		for(int i=0,len=reporttypeArr.length;i<len;i++){
			String reportType = reporttypeArr[i];
			for(Map<String, String> mapItem: reportNameList){
				if(reportType.equals(mapItem.get("reporttype"))){
					reportNameResultList.add(mapItem);
				}
			}
			
		}
		resultMap.put("reportNameArr", reportNameResultList);
		resultMap.put("reportArr", map);
		return ServerResponse.createBySuccess(resultMap);

	}
	
	public Object deleteMyReport(String reportid){
		if(reportExportStatusMapper.deleteReportStatus(reportid)>0){
			return ServerResponse.createBySuccessMessage("删除成功！");
		}
		return ServerResponse.createByErrorMessage("删除失败");
	}

	
	public Object uploadSearchFile(MultipartFile file,String userrealname, String userid){
		FileInputStream writeStream = null; 
		String uploadFileId = UUID.randomUUID().toString();
		String reportName = file.getOriginalFilename();
		String fileName = uploadFileId+reportName;
		String uploadFileName = uploadPath+fileName;
		try {
			writeStream = (FileInputStream) file.getInputStream();
		} catch (IOException e) {
			e.printStackTrace();
		}
		if(POIExcelUtils.writeExcel(writeStream, uploadFileName)&&saveReportStatus(userrealname,"fetch_data",userid,uploadFileId,reportName,fileName)>0){
			return ServerResponse.createBySuccess("上传成功！",uploadFileId);
		}
 		return ServerResponse.createBySuccessMessage("上传失败！");
	}
	
	public String getDownloadTempletName(String searchName){
		return ReportTemplateTypeEnum.getTemplate(searchName);
	}
	
	public List<DvExcelFieldDefinitionEntity> getExcelFieldDefinitionList(String reportType,String dimension){
		return dataBaseExcelDefinitionMapper.queryField(reportType,dimension);
	}
	public List<DvExcelFieldDefinitionEntity> getExcelFieldDefinitionList(String reportType){
		return getExcelFieldDefinitionList(reportType,null);
	}
	public Map<String,String> queryCategory(String reportType){
			Map<String,String> categoryMap  = Maps.newHashMap();
			List<DvExcelFieldDefinitionEntity> dvExcelFieldDefinitionList = dataBaseExcelDefinitionMapper.queryCategory(reportType);
			for(DvExcelFieldDefinitionEntity dvExcelFieldDefinitionEntity: dvExcelFieldDefinitionList){
				categoryMap.put(dvExcelFieldDefinitionEntity.getCategoryId(), dvExcelFieldDefinitionEntity.getCategory());
			}
			return categoryMap;
	}
	public String getSqlFieldString(String reportType,String[] targetArr){
		List<DvExcelFieldDefinitionEntity>  reportFieldDefinition= getExcelFieldDefinitionList(reportType);
		String sqlFieldStr = "";
		for(String target : targetArr){
			for(DvExcelFieldDefinitionEntity fieldItem : reportFieldDefinition){
				String entityName = fieldItem.getEntityName();
				if(target.equals(entityName)){
					sqlFieldStr+=fieldItem.getSqlFieldName()+" as "+fieldItem.getEntityName()+",";
				}
			}
		}
		sqlFieldStr=sqlFieldStr.substring(0, sqlFieldStr.length()-1);
		return sqlFieldStr;
	}
	/**
	 * 
	 * @Description删除多余的上传文件
	 * @param userid
	 * @author yangjun
	 * @Date 2017年8月30日 下午4:56:56
	 */
	public void deleteUploadReport(String userid){
			List<DvReportExportStatus> dvReportExportStatusList = reportExportStatusMapper.queryMyReport(userid);
			List<DvReportImportStatus> dvReportImportStatusList = reportImportStatusMapper.queryReportStatusIdByUserid(userid);
			List<String> uploadFileList = Lists.newArrayList();
			if(dvReportExportStatusList.size()>0){
				for(DvReportExportStatus reportExportStatus : dvReportExportStatusList){
					String fileName = reportExportStatus.getFileName();
					if(StringUtils.isNotBlank(fileName)){
						uploadFileList.add(fileName);
					}
				}
			}
			
			if(dvReportImportStatusList.size()>0){
				for(DvReportImportStatus dvReportImportStatus: dvReportImportStatusList){
					String fileName = dvReportImportStatus.getFileName();
					if(uploadFileList.contains(fileName)){
						continue;
					}else{
						String filePath = uploadPath+fileName;
						File file = new File(filePath);
						if(file.isFile()&&file.exists()){
							file.delete();
						}
					}
				}
			}
	}
	//返回复选框选中项
	public List<Map<String,Object>> HandleCheackBoxStatus(List<String> cheackBoxNameList,String[] selectData){
		List<Map<String,Object>> resultList = Lists.newArrayList();
		if(cheackBoxNameList!=null&&cheackBoxNameList.size()>0){
			Map<String,Object> itemMap = null;
			for(String cheackBoxName : cheackBoxNameList){
				itemMap = Maps.newHashMap();
				itemMap.put("name", cheackBoxName);
				if(selectData!=null&&selectData.length>0){
					itemMap.put("checked", false);
					for(String selectItem : selectData){
						if(cheackBoxName.equals(selectItem)){
							itemMap.put("checked", true);
							break;
						}
					}
				}else{
					itemMap.put("checked", true);
				}
				resultList.add(itemMap);
			}
		}
		return resultList;
	}
	/**
	 * @Description 获取订单平台名字数组
	 * @param ordersourceArr
	 * @param ordersourceList
	 * @return
	 * @author yangjun
	 * @Date 2017年9月26日 下午2:31:06
	 */
	public String[] getOrderSourceName(String[] ordersourceArr,List<Map<String, Object>> ordersourceList){
		Set<String> sourcenameSet = Sets.newHashSet();
		for(String targetOrdersource : ordersourceArr){
			for(Map<String, Object> ordersource : ordersourceList){
				String[] arr = ordersource.get("ordersource").toString().split(",");
				List<String> arrList = Arrays.asList(arr);
				if(arrList.contains(targetOrdersource)){
					sourcenameSet.add(ordersource.get("sourcename").toString());
				}
			}
		}
		
		return sourcenameSet.toArray(new String[sourcenameSet.size()]);
	}
	/**
	 * 获取订单平台ID数组
	 * @Description (TODO这里用一句话描述这个方法的作用)
	 * @param ordersourceNameArr
	 * @param ordersourceList
	 * @return
	 * @author yangjun
	 * @Date 2017年9月26日 下午2:31:24
	 */
	public String[] getOrderSourceArr(String[] ordersourceNameArr,List<Map<String, Object>> ordersourceList){
		Set<String> sourceSet = Sets.newHashSet();
		for(String targetOrderName : ordersourceNameArr){
			for(Map<String, Object> ordersource : ordersourceList){
				String sourcename = ordersource.get("sourcename").toString();
				if(targetOrderName.equals(sourcename)){
					String[] ordersourceArr = ordersource.get("ordersource").toString().split(",");
					for(String o : ordersourceArr){
						sourceSet.add(o);

					}
				}
			}
		}
		
		return sourceSet.toArray(new String[sourceSet.size()]);
	}
	
	public List<String> getTargetNameList(String[] targetArr,String reporttype){
		List<String> targetNameList = Lists.newArrayList();
		List<DvExcelFieldDefinitionEntity> excelFieldDefinitionList = getExcelFieldDefinitionList(reporttype);
		for(String target : targetArr){
			for(DvExcelFieldDefinitionEntity dvExcelFieldDefinitionItem : excelFieldDefinitionList){
				String entityName = dvExcelFieldDefinitionItem.getEntityName();
				String targetName = dvExcelFieldDefinitionItem.getTitle();
					if(target.equals(entityName)){
						targetNameList.add(targetName);
					}
			}
		}
		return targetNameList;
	}
	
}
